package org.study.neo4j.boot.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.study.neo4j.boot.model.Student;
import org.study.neo4j.boot.repository.StudentRepository;

import java.util.List;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年04月09日
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Service
public class StudentService {
    private final StudentRepository studentRepository;

    public Student saveStudent(Student student) {
        return studentRepository.save(student);
    }

    public List<Student> getAllStudents() {
        return studentRepository.findAll();
    }

    public Student getStudentById(Long id) {
        return studentRepository.findById(id).orElse(null);
    }

    public List<Student> getStudentsByCourseCode(String courseCode) {
        return studentRepository.findByCourseCode(courseCode);
    }

    public List<Student> getStudentsByTeacherName(String teacherName) {
        return studentRepository.findByTeacherName(teacherName);
    }

    public void deleteStudent(Long id) {
        studentRepository.deleteById(id);
    }
}
